package cn.itcast.service.impl;

import cn.itcast.dao.StandardDao;
import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @Author： ~Mr·Weng~
 * @CreateTime： 2019年-01月-20日  15:53
 * Look at the wine in the glass toast the rich first.
 */
@Service
public class StandardServiceImpl implements StandardService {

    @Autowired
    private StandardDao standardDao;

    /**
     * 保存和修改
     * @param standard
     */
    @Override
    @Transactional
    public void save(Standard standard) {
        standardDao.save(standard);
    }

    /**
     * 分页查询
     * @param page
     * @param rows
     * @return
     */
    @Override
    public Page<Standard> pageQuery(int page, int rows) {
        PageRequest pageable = PageRequest.of(page-1, rows);
        return standardDao.findAll(pageable);
    }

    /**
     * 删除或批量删除
     * @param strId
     */
    @Override
    public void deleById(String strId) {
        String[] idStr = strId.split(",");
        for (String str : idStr) {
            int id = Integer.parseInt(str);
            standardDao.deleteById(id);
        }
    }

    /**
     * 查询全部
     */
    @Override
    public List<Standard> standard_findAll() {
        return standardDao.findAll();
    }
}
